package com.shujia

class P(name: String) {
  val _name: String = name
}

// 像接口：可以被with多次，即一个类可以同时实现多个trait
// 又像抽象类：可以定义具体的属性及方法，以及抽象的方法
trait K {
  val _gender1: String = "男"

  def isEqualGender1(g: String): Boolean

  def isNotEqualGender1(g: String): Boolean = {
    !isEqualGender1(g)
  }
}


trait KK {
  val _gender2: String = "男"

  def isEqualGender2(g: String): Boolean

  def isNotEqualGender2(g: String): Boolean = {
    !isEqualGender2(g)
  }
}

class Q(name: String, age: Int) extends P(name) with K with KK {
  val _age: Int = age

  override def isEqualGender1(g: String): Boolean = {
    _gender1 == g
  }

  override def isEqualGender2(g: String): Boolean = {
    _gender2 == g
  }
}

object Demo23Trait {
  def main(args: Array[String]): Unit = {
    val zs: Q = new Q("zs", 20)
    println(zs.isEqualGender1("男"))
    println(zs.isEqualGender1("女"))
    println(zs.isEqualGender2("女"))
    println(zs.isEqualGender2("女"))

  }

}
